from exts import ma
from models import CMAParams
from marshmallow import fields, validate, EXCLUDE
from marshmallow_sqlalchemy import SQLAlchemyAutoSchema
class CMAParamsSchema(SQLAlchemyAutoSchema):
    class Meta:
        model = CMAParams
        load_instance = True  # 允许反序列化为 User 实例
        fields = ("id", "category", "parameterName", "standardNo", "standardMethod", "qualificationDate", "actualLimit", "remarks", "exportError", "description")# 序列化时仅返回这几个字段
        # 忽略字段
        # exclude = ("password",)
        unknown = EXCLUDE  # 在 load 时忽略未定义的字段
    # 验证
    category = fields.String(required=True, validate=validate.Length(min=2, max=100))